zipl: remove 'sdboot' image before generating new one
authorNikita Dubrovskii <nikita@linux.ibm.com>
Mon, 3 Feb 2025 11:51:11 +0000 (12:51 +0100)
committerNikita Dubrovskii <nikita@linux.ibm.com>
Mon, 3 Feb 2025 12:31:17 +0000 (13:31 +0100)
src/libostree/ostree-bootloader-zipl.c

index f0c18cbcfc134caa05aaf055035621f57df759b0..bfa7823f8372b4a2953c22b08e78a22ec171412c 100644 (file)
 #include "ostree-libarchive-private.h"
 #include "ostree-sysroot-private.h"
 #include "otutil.h"
+#include <fcntl.h>
 #include <gio/gunixinputstream.h>
 #include <string.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
 #define SECURE_EXECUTION_SYSFS_FLAG "/sys/firmware/uv/prot_virt_guest"
 #define SECURE_EXECUTION_PARTITION "/dev/disk/by-label/se"
@@ -354,6 +356,12 @@ _ostree_secure_execution_generate_sdboot (gchar *vmlinuz, gchar *initramfs, gcha
     return FALSE;
   g_autofree gchar *ramdisk_filename = g_strdup_printf ("/proc/%d/fd/%d", self, ramdisk.fd);
 
+  // Since s390-tools commit f4cf4ae6ebb1 (Remove genprotimg-C and switch to genprotimg-Rust
+  // implementation) 'genprotimg' is just a symlink to 'pvimg create', which by default doesn't
+  // overwrite the output image, but introduces the '--overwrite' flag for this. Let's silently
+  // remove the file to support both tools
+  (void)unlink (SECURE_EXECUTION_BOOT_IMAGE);
+
   g_autoptr (GPtrArray) argv = g_ptr_array_new ();
   g_ptr_array_add (argv, "genprotimg");
   g_ptr_array_add (argv, "-i");